#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QLocale>
#include <QTranslator>
#include "main.h"
#include "mp4.h"
#include "mytimer.h"
#include <iostream>
#include <QTextCodec>

QString             configFile = "C:/Users/Crabor/QtProjects/just-tags/doc/just_tags.conf";
Config              config;
QVector<Mp4>        liveMp4s;
QMutex              liveMp4sMutex;
QVector<Mp4>        deadMp4s;
QMutex              deadMp4sMutex;
QVector<QString>    allMp4Name;
QMutex              allMp4NameMutex;
QRegularExpression  rMp4("(\\.mp4)|(\\.MP4)$");
QTextCodec *code = QTextCodec::codecForName("GB2312");

int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
    QGuiApplication app(argc, argv);
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
    if (loadConfig(configFile, config) == -1) {
        return -1;
    }
//    for (QString dirName : config.dirs) {
//        std::cout << dirName.toStdString() << std::endl;
//    }
//    MyTimer timer;
//    timer.start();

    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);
    engine.setProperty("_test", QString("Hello"));


    return app.exec();
}
